package com.speily.lock.controller;

import cn.hutool.core.lang.Dict;
import com.speily.lock.annotation.RateLimiter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * <p></p>
 *
 * @author SPL
 * @since 2019/12/30 16:32
 */
@RestController
@Slf4j
public class Testcontroller {

    @RateLimiter(count = 5)
    @GetMapping("/test1")
    public Dict test1() {
        return Dict.create().set("msg", "hello,world!").set("description", "默认限流：5次/分钟");
    }

    @GetMapping("/test2")
    public Dict test2() {
        return Dict.create().set("msg", "hello,world!").set("description", "无限流，一直在");
    }

    @RateLimiter(count = 2, key = "测试自定义key")
    @GetMapping("/test3")
    public Dict test3() {
        return Dict.create().set("msg", "hello,world!").set("description", "自定义key值");
    }

    @RateLimiter(key = "test",count = 5,timeUnit = TimeUnit.SECONDS, timeout = 10)
    @GetMapping("/test4")
    public Dict test4() {
        return Dict.create().set("msg", "hello,world!").set("description", "10秒5次~");
    }


}
